package word

import (
	"strings"
	"unicode"
)

const (
	ModeUpper                      = iota + 1 // 全部转大写
	ModeLower                                 // 全部转小写
	ModeUnderscoreToUpperCamelCase            // 下划线转大写驼峰
	ModeUnderscoreToLowerCamelCase            // 下划线转小写驼峰
	ModeCamelCaseToUnderscore                 // 驼峰转下划线
)

// 1.全部转大写
func ToUpper(s string) string {
	return strings.ToUpper(s)
}

// 2.全部转小写
func ToLower(s string) string {
	return strings.ToLower(s)
}

// 3.下划线单词转为大写驼峰
func UnderscoreToUpperCamelCase(s string) string {
	//方式一
	s = strings.Replace(s, "_", " ", -1)
	s = strings.Title(s)
	return strings.Replace(s, " ", "", -1)

	//方式二
	//strs := strings.Split(s, "_")
	//var strs2 = make([]string, 1, 1)
	//for _, str := range strs {
	//	strs2 = append(strs2, strings.Title(str))
	//}
	//return strings.Join(strs2, "")
}

// 4.下划线单词转为小写驼峰
func UnderscoreToLowerCamelCase(s string) string {
	s = UnderscoreToUpperCamelCase(s)
	return string(unicode.ToLower(rune(s[0]))) + s[1:]
}

// 5.驼峰转为小写驼峰
func CamelCaseToUnderscore(s string) string {
	var output []rune
	for i, r := range s {
		if i == 0 {
			output = append(output, unicode.ToLower(r))
			continue
		}
		if unicode.IsUpper(r) {
			output = append(output, '_')
		}
		output = append(output, unicode.ToLower(r))
	}
	return string(output)
}
